package com.github.apollo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.codec.CharSequenceEncoder;
import org.springframework.core.codec.StringDecoder;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.config.WebFluxConfigurer;

/**
 * 配置WebFlux
 * @author Stephen
 * @since 2018-02-01
 */
@Configuration
@EnableWebFlux
public class WebConfig implements WebFluxConfigurer {

    @Override
    public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
        configurer.registerDefaults(false);
        configurer.customCodecs().decoder(StringDecoder.textPlainOnly(true));
        configurer.customCodecs().decoder(new Jackson2JsonDecoder());
        configurer.customCodecs().encoder(CharSequenceEncoder.textPlainOnly());
        configurer.customCodecs().encoder(new Jackson2JsonEncoder());
    }

}
